//待预约 退款关闭订单
<template>
  <div class="addPrice">
    <el-dialog
      title="确认退款关闭订单"
      :visible.sync="visible"
      width="600px"
      modal-append-to-body
      center
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="110px"
        label-position="left"
      >
        <p>
          订单下单师傅金额：{{
            orderInfo && orderInfo.payAmount | filterPriceFormat
          }}元
        </p>
        <p>累计加价：20元</p>
        <el-form-item label="退款金额" prop="saleAmount">
          <el-input-number
            :controls="false"
            :precision="2"
            :step="1"
            :min="0.01"
            :max="999"
            v-model="ruleForm.saleAmount"
          ></el-input-number
          >元
        </el-form-item>
        <el-form-item label="退款关闭原因" prop="refundReason">
          <el-select v-model="ruleForm.refundReason" placeholder="请选择">
            <el-option v-for="item in reasonList" :key="item.dictLabel" :label="item.dictLabel" :value="item.dictLabel"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="描述" prop="problem">
          <el-input type="textarea" v-model="ruleForm.problem"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="info" @click="back">返回</el-button>
        <el-button type="danger" @click="submit">退款</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { apiDictRefundCloseReason } from "@/api/order.js";
export default {
  components: {},
  props: {
    orderInfo: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    const checkOrderPrice = (rule, value, callback) => {
      console.log(this.orderInfo.payAmount);
      if (value > this.orderInfo.payAmount / 100) {
        callback(new Error("退款金额不得大于实付金额于累计加价金额之和"));
      } else {
        callback();
      }
    };

    return {
      visible: false,
      ruleForm: {
        saleAmount: undefined,
        refundReason: "",
        problem: "",
      },
      reasonList:[],
      rules: {
        saleAmount: [
          { required: true, message: "请填写退款金额", trigger: "blur" },
          { validator: checkOrderPrice, trigger: "blur" },
        ],
        refundReason: [
          { required: true, message: "请选择加价原因", trigger: "blur" },
        ],
        problem: [{ required: true, message: "请填写描述", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      apiDictRefundCloseReason().then((res) => {
        this.reasonList = res.data;
      });
    },
    onShow() {
      this.visible = true;
    },
    back() {
      this.$refs.ruleForm.resetFields();
      this.visible = false;
    },
    submit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          console.log(this, "退款");
          this.$emit("refundClose", this.ruleForm);
          this.visible = false;
          this.$nextTick(() => {
            this.$refs.ruleForm.resetFields();
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

